package com.zp.system.dubbo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zp.common.core.utils.StringUtils;
import com.zp.system.api.RemoteOrgDictDataService;
import com.zp.system.api.bo.SysOrgDictBo;
import com.zp.system.api.entity.SysOrgDict;
import com.zp.system.api.vo.SysOrgDictVo;
import com.zp.system.mapper.SysOrgDictMapper;
import com.zp.system.service.ISysOrgDictService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;

/**
 * 操作日志记录
 *
 * @author zhang peng
 */
@RequiredArgsConstructor
//@Service
@DubboService
public class RemoteOrgDictDataServiceImpl implements RemoteOrgDictDataService {

    private final SysOrgDictMapper sysOrgDictMapper;

    private final ISysOrgDictService sysOrgDictService;

    @Override
    public List<SysOrgDict> listNotExistOrgData(String type, List<String> collect) {
        List<SysOrgDict> list = sysOrgDictMapper.selectList(Wrappers.<SysOrgDict>lambdaQuery()
                .eq(SysOrgDict::getType, type)
                .notIn(CollectionUtil.isNotEmpty(collect), SysOrgDict::getValue, collect)
                .orderByAsc(SysOrgDict::getSort)
        );
        return list;
    }

    /**
     * 查询存在的字典数据
     *
     * @param collect
     * @return
     */
    @Override
    public List<SysOrgDict> selectExistOrgData(List<String> collect) {
        return sysOrgDictMapper.selectList(Wrappers.<SysOrgDict>lambdaQuery()
                .in(CollectionUtil.isNotEmpty(collect), SysOrgDict::getOrgDictId, collect)
        );
    }

    @Override
    public List<SysOrgDict> selectList(SysOrgDict sysOrgDict) {
        return sysOrgDictMapper.selectList(Wrappers.<SysOrgDict>lambdaQuery()
                .eq(SysOrgDict::getOrgId, sysOrgDict.getOrgId())
                .eq(SysOrgDict::getType, sysOrgDict.getType())
                .eq(StringUtils.isNotBlank(sysOrgDict.getValue()), SysOrgDict::getValue, sysOrgDict.getValue())
        );
    }

    @Override
    public SysOrgDictVo getDictPrices(SysOrgDict sysOrgDict) {
        return sysOrgDictService.getDictPrices(BeanUtil.toBean(sysOrgDict, SysOrgDictBo.class));
    }
}
